package com.hq.thread.test1;

/**
 * @ClassName Test1
 * @Description
 * 现在有T1、T2、T3三个线程，你怎样保证T2在T1执行完后执行，T3在T2执行完后执行？
 * 目的是检测你对”join”方法是否熟悉
 * @Author huangzl
 * @Date 2019/4/8 12:40
 * @Version 1.0
 **/
public class Test1 {

    public static void main(String[] args) {

        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("t1 finished");
            }
        });

        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    t1.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("t2 finished");
            }
        });

        Thread t3 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    t2.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("t3 finished");
            }
        });
        t3.start();
        t2.start();
        t1.start();


    }
}